import { NgModule } from '@angular/core'
import { Routes, RouterModule } from '@angular/router'

import { RoleListComponent } from './list/list.component'
import { RoleNewComponent } from './new/new.component'
import { RoleDetailComponent } from './detail/detail.component'
import { NewRouterGuardClass } from '@shared/classes/NewRouterGuardClass'
import { RoleDetailUsersComponent } from './detail/users/users.component'
import { RoleDetailOpenFunctionComponent } from './detail/open-function/open-function.component'
import { ERoleRoute } from './role.interface'
import { ListReuseGuardClass } from '@shared/classes/ListReuseGuardClass'

const routes: Routes = [
  { path: '', redirectTo: 'list', data: { title: '角色列表' }, component: RoleListComponent, pathMatch: 'full' },
  {
    path: 'list',
    component: RoleListComponent,
    pathMatch: 'full',
    canActivate: [ListReuseGuardClass],
    data: {
      title: '角色列表',
      titleI18n: 'MENU.ROLES',
      reuse: true,
    },
  },
  {
    path: 'new',
    component: RoleNewComponent,
    canDeactivate: [NewRouterGuardClass],
    data: {
      breadcrumb: 'GENERAL.INFO.BREADCRUMB.CREATE',
      title: '新增角色',
      titleI18n: 'ROLE.TITLE.CREATE',
      routeName: ERoleRoute.CreateRole,
    },
  },
  {
    path: ':id',
    component: RoleDetailComponent,
    children: [
      { path: '', redirectTo: 'users', pathMatch: 'full' },
      {
        path: 'users',
        component: RoleDetailUsersComponent,
        data: {
          titleI18n: 'ROLE.TITLE.DETAIL',
        },
      },
      {
        path: 'open-function',
        component: RoleDetailOpenFunctionComponent,
        data: {
          titleI18n: 'ROLE.TITLE.DETAIL',
        },
      },
    ],
    data: {
      breadcrumb: 'GENERAL.INFO.BREADCRUMB.DETAIL',
      titleI18n: 'ROLE.TITLE.DETAIL',
    },
  },
  {
    path: 'copy/from/:id',
    component: RoleNewComponent,
    canDeactivate: [NewRouterGuardClass],
    data: {
      breadcrumb: 'ROLE.TITLE.COPY',
      title: '复制角色',
      titleI18n: 'ROLE.TITLE.COPY',
      routeName: ERoleRoute.CopyRole,
    },
  },
]

@NgModule({
  imports: [RouterModule.forChild(routes)],
  exports: [RouterModule],
})
export class RoleRoutingModule {}
